package com.chixing.day16_io;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.Arrays;

public class ReaderDemo {
    public static void main(String[] args){
        //1.创建字符读取流对象
        Reader reader = null;
        try {
            reader = new FileReader("f:/test1/hello1.txt");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        //2.读取数据
        char[] chars = new char[1024];
        int size=0;

        int temp;
        while (true) {
            try {
                if ((temp = reader.read()) == -1) break;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }finally {
                try {
                    reader.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            chars[size++] = (char) temp;
            System.out.println(Arrays.toString(chars));

        }

        //3.关闭流
    }
}
